layui.use(['form', 'layer', 'jquery'], function() {
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : top.layer
	$ = layui.jquery;

	$(".loginBody .seraph").click(function() {
		layer.msg("这只是做个样式，至于功能，你见过哪个后台能这样登录的？还是老老实实的找管理员去注册吧", {
			time: 5000
		});
	})

	// 清除字符串两边的空格
	function trim(str) { //删除左右两端的空格
		return str.replace(/(^\s*)|(\s*$)/g, "");　　
	}
	//注册按钮
	form.on("submit(login)", function(data) {

		var username = trim(document.getElementById("userName").value);
		var passsword1 = trim(document.getElementById("password1").value);
		var passsword2 = trim(document.getElementById("password2").value);

		var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
		var sign = true;
		if(username == "") {
			layer.msg("用户名不能为空", {
				time: 2000
			});
			sign = false;
			return false;

		}

		if(!myreg.test(username)) {
			layer.msg("请输入有效的手机号码", {
				time: 2000
			});
			sign = false;
			return false;
		}

		if(passsword2 !== passsword1) {
			layer.msg("两次密码不匹配", {
				time: 2000
			});
			sign = false;
			return false;
		}

		if(sign) {
			console.log(severUrl)
			$.post(severUrl + "manage_regist", {
				'user_name': username,
				'pass_word': passsword1
			}, function(data) {
				console.log(data)
				layer.msg(data.data.message, {
				time: 5000
			});
			})
		}

		setTimeout(function() {
			//			window.location.href = "../../index.html";
		}, 1000);
		return false;
	})

	//表单输入效果
		$(".loginBody .input-item").click(function(e) {
			e.stopPropagation();
			$(this).addClass("layui-input-focus").find(".layui-input").focus();
		})
		$(".loginBody .layui-form-item .layui-input").focus(function() {
			$(this).parent().addClass("layui-input-focus");
		})
		$(".loginBody .layui-form-item .layui-input").blur(function() {
			$(this).parent().removeClass("layui-input-focus");
			if($(this).val() != '') {
				$(this).parent().addClass("layui-input-active");
			} else {
				$(this).parent().removeClass("layui-input-active");
			}
		})
})